package spring.cloud.canary.demo.rule;

import jk.framework.canary.core.po.RouteContext;
import jk.framework.spring.cloud.canary.loadbalancer.api.LoadBalanceRouteRule;
import org.springframework.cloud.client.loadbalancer.RequestData;
import org.springframework.util.ObjectUtils;

import java.util.Collection;

public class DemoHeaderCanaryRule implements LoadBalanceRouteRule {
    @Override
    public boolean isAllow(RouteContext<RequestData> context) {
        Collection<String> labels = context.getLabels("header.abc");
        if(ObjectUtils.isEmpty(labels) || !labels.contains("123")){
            System.err.println("不符合header规则");
            return false;
        }
        System.err.println("符合header规则");
        return true;
    }
}
